package koction.model.product;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

@Service
public class ProductServiceImpl implements ProductService {
	@Resource(name="productDaoImpl")
	private ProductDao productDao;
	
	public List<ProductVO> getProductListByCategory(String category){
		return productDao.getProductListByCategory(category);
	}
	
	public List<ProductVO> searchProductListByName(String name,String category){
		List<ProductVO> list=null;
		if(category==null||category==""){
		list=productDao.searchProductListByName(name);
		}else{
			Map map=new HashMap();
			map.put("productName", name);
			map.put("productCategory", category);
			list=productDao.searchProductByNameAndCategory(map);
		}
		return list;
	}
	/*public List<ProductVO> searchProductListByMaker(String maker,String category){
		return productDao.searchProductListByMaker(maker);
	}
	
	public List<ProductVO> findProductListByPrice(int min, int max,String category){
		Map map=new HashMap();
		map.put("min", min);
		map.put("max", max);
		return productDao.findProductListByPrice(map);
	}*/
	public ProductVO getProductInfo(String productId){
		return productDao.getProductInfo(productId);
	}
	

	public List<ProductVO> searchProductListByOrder(String name,
			String category, String order){
		List<ProductVO> list=null;
		Map map=new HashMap();
		if(name==""||name==null){
			
			map.put("productCategory", category);			
			
			if(order.equals("priceAsc")){
				list=productDao.getProductListByCategoryAndPriceAscOrder(map);
			}else if(order.equals("priceDesc")){
				list=productDao.getProductListByCategoryAndPriceDescOrder(map);
			}else if(order.equals("star")){
				list=productDao.getProductListByCategoryAndStarOrder(map);
			}
			
			
			
		}else{
			
		if(category==""||category==null){
			map.put("productName", name);
			if(order.equals("priceAsc")){
				list=productDao.getProductListByNameAndPriceAscOrder(map);
			}else if(order.equals("priceDesc")){
				list=productDao.getProductListByNameAndPriceDescOrder(map);
			}else if(order.equals("star")){
				list=productDao.getProductListByNameAndStarOrder(map);
			}
			
		}else{
			map.put("productCategory", category);
			map.put("productName", name);
			
			if(order.equals("priceAsc")){
				list=productDao.getProductListByAllAndPriceAscOrder(map);
			}else if(order.equals("priceDesc")){
				list=productDao.getProductListByAllAndPriceDescOrder(map);
			}else if(order.equals("star")){
				list=productDao.getProductListByAllAndStarOrder(map);
			}
			
		}
			
		}
		return list;
	}
	
}
